package com.caiden_micheal.position.web;

import com.caiden_micheal.base.aop.annotation.PermissionVerify;
import com.caiden_micheal.base.domain.AjxResult;
import com.caiden_micheal.position.vo.*;
import com.caiden_micheal.position.service.PositionService;
import com.caiden_micheal.user.domain.PositionOrgUser;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
@RequestMapping("/position")
public class PositionController {
    @Autowired
    private PositionService positionService;

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignPosition", "sys:positionManagement"})
    @PostMapping("/positionQuery")
    public AjxResult positionInfoPageQuery(@RequestBody PositionQueryVO positionQueryVO) {
        return AjxResult.success(positionService.findPositionsByCondition(positionQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:add"})
    @PostMapping("/addPosition")
    public AjxResult addPosition(@RequestBody AddPositionVO addPositionVO) {
        return positionService.addPosition(addPositionVO);
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:edit"})
    @PostMapping("/editPosition")
    public AjxResult editPosition(@RequestBody EditPositionVO editPositionVO) {
        return positionService.editPosition(editPositionVO);
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:assignMember"})
    @PostMapping("/addAllocationPosition")
    public AjxResult addAllocationPosition(@RequestBody PositionOrgUser positionOrgUser) {
        return positionService.addAllocationPosition(positionOrgUser);
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:assignMember"})
    @PostMapping("/removePositionUser")
    public AjxResult removePositionUser(@RequestBody RemovePositionUserVO removePositionUserVO) {
        return positionService.removePositionUser(removePositionUserVO);
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:delete"})
    @PostMapping("/positionRemove")
    public AjxResult positionRemove(@RequestBody PositionRemoveVO positionRemoveVO) {
        return positionService.removePosition(positionRemoveVO);
    }

    @PostMapping("/findPosiitonTreeByOrg")
    public AjxResult findPosiitonTreeByOrg(@RequestBody FindPosiitonTreeByOrgVO data) {
        return positionService.findPosiitonTreeByOrg(data.getOrgId());
    }
}
